All files / src/app/api/admin/components/[name]/diagnosis route.ts

100% Statements 10/10
100% Branches 4/4
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86      1x                               1x                                                                                                   17x 17x   15x 15x 15x   11x                  
import { NextRequest, NextResponse } from "next/server";
import { requireAuth, isAuthError } from "@/lib/auth-guard";
 
export const dynamic = "force-dynamic";
 
interface Diagnosis {
  name: string;
  severity: "critical" | "warning" | "healthy" | "unknown";
  summary: string;
  cause: string;
  bootError?: string;
  remediation?: string;
  trackingIssue?: string;
}
 
// Static diagnosis map. These boot errors are deterministic (config-driven, not
// transient), so a static catalogue is more useful than tailing logs — which
// is also unavailable on this deployment because Log Analytics is disabled
// (ADR-018, Workaround B).
const KNOWN_DIAGNOSES: Record<string, Diagnosis> = {
  "mvhd-controlplane": {
    name: "mvhd-controlplane",
    severity: "critical",
    summary: "JVM crashes at boot — Jetty port collision.",
    cause:
      "EDC's controlplane needs four distinct Jetty ports (web 8080 / management 8081 / protocol 8082 / control 8083). " +
      "ACA Container Apps' default ingress exposes a single target port, so scripts/azure/04-edc-services.sh forces all four onto 8081. " +
      "Jetty's PortMappingRegistryImpl rejects the duplicate binding and the JVM exits before any HTTP listener comes up.",
    bootError:
      "java.lang.IllegalArgumentException: A binding for port 8081 already exists\n" +
      "  at org.eclipse.edc.web.jetty.PortMappingRegistryImpl.register(PortMappingRegistryImpl.java:35)\n" +
      "  at org.eclipse.edc.virtual.connector.controlplane.api.management.ManagementApiConfigurationExtension.initialize(...)",
    remediation:
      "Restart will not fix this — the failure is config-driven, not transient. Resolution requires either configuring ACA " +
      "additionalPortMappings (multi-port ingress) or migrating EDC services to AKS. Currently scaled to min-replicas=0 to avoid cost.",
    trackingIssue:
      "https://github.com/ma3u/MinimumViableHealthDataspacev2/issues/25",
  },
  "mvhd-identityhub": {
    name: "mvhd-identityhub",
    severity: "critical",
    summary: "JVM boots, but HTTP listener doesn't reach ACA target-port.",
    cause:
      "IdentityHub configures five distinct web ports (7080 default, 7081 identity, 7082 credentials, 7083 did, 7084 sts). " +
      "Same single-port mismatch as controlplane — ACA only exposes target-port 7081, so the IdentityAPI on /api/identity is " +
      "either unreachable or shadowed depending on which port collapses to which path. TCK probes time out.",
    remediation:
      "Same as controlplane — multi-port ACA or AKS. Currently scaled to min-replicas=0.",
    trackingIssue:
      "https://github.com/ma3u/MinimumViableHealthDataspacev2/issues/25",
  },
  "mvhd-issuerservice": {
    name: "mvhd-issuerservice",
    severity: "critical",
    summary: "Same multi-port mismatch as identityhub.",
    cause:
      "IssuerService inherits the IdentityHub OAuth extension and the same multi-port web layout. " +
      "Even though the JVM boots past dependency injection, the Admin API is not reachable through ACA's single target-port.",
    remediation:
      "Same as controlplane / identityhub. Currently scaled to min-replicas=0.",
    trackingIssue:
      "https://github.com/ma3u/MinimumViableHealthDataspacev2/issues/25",
  },
};
 
export async function GET(
  _req: NextRequest,
  { params }: { params: Promise<{ name: string }> },
) {
  const auth = await requireAuth(["EDC_ADMIN"]);
  if (isAuthError(auth)) return auth;
 
  const { name } = await params;
  const known = KNOWN_DIAGNOSES[name];
  if (known) return NextResponse.json(known);
 
  return NextResponse.json({
    name,
    severity: "healthy",
    summary: "No known boot issue for this component.",
    cause:
      "This component is not in the known-issue catalogue. If you observe " +
      "instability, check Azure Portal → Container App → Log stream for live diagnostics.",
  } as Diagnosis);
}